package company;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class ThreeSum1 {
    public static void main(String[] args) {

        // 输入
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String replace = s.replace("[", "");
        String replace1 = replace.replace("]", "");
        String[] split = replace1.split(",");
        int len = split.length;
        int[] digit = new int[len];
        for (int i = 0; i < len; i++) {
            digit[i] = Integer.parseInt(split[i]);
        }

        // 获取符合条件的组合
        List<List<Integer>> list = threeSum(digit);

        // 打印
        if (list.size() == 0) {
            System.out.println("[]");
        }
        System.out.print("[[");
        int size = list.size();
        for (int i = 0; i < size; i++) {
            List<Integer> sublist = list.get(i);
            int size1 = sublist.size();
            for (int j = 0; j < size1; j++) {
                System.out.print(sublist.get(j));
                if (j < size1 - 1) {
                    System.out.print(",");
                }
            }
            if (i < size - 1) {
                System.out.print("],[");
            } else {
                System.out.print("]]");
            }
        }
    }

    public static List<List<Integer>> threeSum(int[] nums) {
        // 排序
        Arrays.sort(nums);
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> subList;
        int len = nums.length;
        for (int i = 0; i < len-2; i++) {
            int a = nums[i];
            // 定义指针
            int left = i + 1;
            int right = len - 1;

            // 双指针
            for (int j = left; j < len; j++) {
                if (left < right) {
                    subList = new ArrayList<>();
                    // b+c +a < 0
                    if (nums[left] + nums[right] + a < 0) {
                        left++;
                    } else if (nums[left] + nums[right] + a == 0) {
                        // b+c+a = 0
                        subList.add(a);
                        subList.add(nums[left]);
                        subList.add(nums[right]);
                        if (!list.contains(subList)) {
                            list.add(subList);
                        }
                    } else if (nums[left] + nums[right] + a > 0) {
                        right--;
                    }
                }
            }
        }
        return list;
    }
}
